package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func producer(ch chan<- interface{}) {
	defer wg.Done()
	for i := 0; i < 5; i++ {
		ena := []string{"鸡腿", "鸡翅"}
		ch <- ena[0]
		ch <- ena[1]
		time.Sleep(time.Millisecond * 10)
	}
	close(ch)
}
func consumer(ch <-chan interface{}) {
	defer wg.Done()
	for i := 0; i < 10; i++ {
		i := <-ch
		fmt.Printf("消费者购买了：%s\n", i)
	}
}
func main() {
	wg.Add(2)
	var ch = make(chan interface{}, 100)
	go producer(ch)
	go consumer(ch)
	wg.Wait()
}
